package com.smt.ejb3.tutoria.client;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.smt.ejb3.tutoria.entitybean.many2one.bidirection.Company2;
import com.smt.ejb3.tutoria.entitybean.many2one.bidirection.Employee2;
import com.smt.ejb3.tutoria.service.MappingService;

public class Company2Client {
	public static void main(String[] args) {
		Date dt = new Date();
		
		Company2 company = new Company2();
		company.setName("IBM1");
		
		
		Employee2 emp = new Employee2();
		emp.setName("Old Sun");
		emp.setHireDate(dt);
		emp.setCompany(company);
		
		Employee2 emp2 = new Employee2();
		emp2.setName("Old Change");
		emp2.setHireDate(dt);
		emp2.setCompany(company);
		
		Set<Employee2> employees = new HashSet<Employee2>();
		employees.add(emp);
		employees.add(emp2);
		company.setEmployees(employees);
		
		try {
			InitialContext ctx = new InitialContext();

			MappingService service = (MappingService) ctx
					.lookup("MappingServiceImpl/remote");
			
			
			company = service.saveCompany2(company);
//			company = service.findCompany2(3);
//			System.out.println(company.getName());
			for(Employee2 e: company.getEmployees()){
				System.out.print(e.getName()+" ");
			}
			
		} catch (NamingException ex) {
			ex.printStackTrace();
		}
	}
}
